<?php
require "../gobal.php";


    $gridid=$_GET["gridid"];
    
    $prefix=$gridid;
    
    $mode=$_GET["mode"];

    $where="where oper_state!='cancel'";
    
    if($mode=="3M"){
        
        $where.=" and created_at between date_sub(now(),interval 3 month) and now()";
        
    }
    
	$sql="select * from order_sum_detail $where order by created_at desc";
    //$rows=fetch_rows($sql);
	//$data=json_encode($rows);

    $url="ajax.php?action=gridOrderSum&mode=$mode";

    $fun_doBatchRemove=$prefix."__doBatchRemove";
    
   

?>

<script>
    
    function <?php echo $fun_doBatchRemove; ?>(){
        
        var dg=$("#<?php echo $gridid;?>");
        
        var srows=dg.datagrid("getSelections");
        
        var oids="",codes="";
        
        var srows_length=srows.length;
        
        if(srows_length<=0){
            alert("請至少選擇一條訂單");return;
        }
        
        for(var i=0;i<srows.length;i++){
            
            var srow=srows[i];
            oids+=srow["id"]+",";
            codes+=srow["code"]+",";
        }
        
        var msg="確認要作廢以下"+srows_length+"張訂單:"+codes+"?";
        if(confirm(msg)){
            var url="ajax.php?action=doCancelOrder";
            var pdata={oids:oids};
            $.getJSON(url,pdata,function(json){
                //alert(str);
                //var json=eval('('+str+')');
                alert(json["msg"]);
                //window.location.reload();
                dg.datagrid("reload");
            });
            //window.location.reload();
        }
        
        //alert(srows.length);
        
    }
    
</script>


<table id="<?php echo $gridid; ?>" class="easyui-datagrid" data-options='fit:true,pagination:true,rownumbers:false,fitColumns:true,rownumbers:true,ctrlSelect:true,pageSize:30,multiSort:true
									,idField:"id"		 ,url:"<?php echo $url; ?>"
											 ,view: detailview,
    detailFormatter: function(rowIndex, order_sum){
        var content= "<table>";
        var service_method=order_sum["service_method"];
		if(service_method=="express"){
        content+="<tr><th>快递单号</th><td>"+order_sum["express_code"]+"<td></tr>"
		+"<tr><th>发件人</th><td>"+order_sum["express_sender_name"]+"<td></tr>"
		+"<tr><th>寄回地址</th><td>"+order_sum["express_sender_address"]+"<td></tr>"
		+"<tr><th>联系电话</th><td>"+order_sum["express_sender_tel"]+"<td></tr>";
        }else{
          content+="<tr><th>联系人</th><td>"+order_sum["visit_contact_realname"]+"<td></tr>"
		+"<tr><th>手机号</th><td>"+order_sum["visit_contact_tel"]+"<td></tr>"
		+"<tr><th>详细地址</th><td>"+order_sum["visit_contact_address"]+"<td></tr>"
		+"<tr><th>上门时间</th><td>"+order_sum["visit_arrive_at"]+"<td></tr>";
		} 
	    content+="</table>";
        return content;
											 }
	,									toolbar: [{
		iconCls: "icon-remove",
		text:"批量作废",
		handler: <?php echo $fun_doBatchRemove ; ?>
	    },{
	    text:"使用幫助",
		iconCls: "icon-help",
		handler: function(){alert("多選請使用ctrl+左擊")}
	}]	 
											 
											 '>
    <thead>
        <tr>
            
            <th data-options="field:'code'">订单号</th>
			<th data-options="field:'order_type',formatter:function(code){ var text=DICT_ORDERTYPE_NAME[code]; return text; }">订单类型</th>
			<th data-options="field:'service_method',formatter:function(code){ var text=DICT_SERVICE_NAME[code]; return text; }">服务方式</th>
            <th data-options="field:'device_name'">设备</th>
			<th data-options="field:'device_color',formatter:function(code){ var text=DICT_COLOR_NAME[code]; return text; }">颜色</th>
            <th data-options="field:'total_price'">预估总价</th>
			<th data-options="field:'remark'">明细</th>
			<th data-options="field:'created_at'">创建时间</th>
			<th data-options="field:'pay_stats'">支付状态</th>
			<th data-options="field:'rate_score'">服务评分</th>
        </tr>
    </thead>

</table>


